package com.swt.gap.controller;

import com.swt.gap.common.graph.GraphNeo4jVO;
import com.swt.gap.common.graph.RelEventNode;
import com.swt.gap.model.vo.EventNodeRelMediaVO;
import com.swt.gap.model.vo.EventRelDocVO;
import com.swt.gap.model.vo.graph.NetworkAnalyseVO;
import com.swt.gap.service.EventTimingAnalysisService;
import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 请填写说明
 *
 * @author sx
 * @date 2020/6/19 17:22
 */
@Api(tags = "事件时序分析")
@RestController
@RequestMapping("/event-timing")
public class EventTimingAnalysisController {

    private final EventTimingAnalysisService eventTimingAnalysisService;

    public EventTimingAnalysisController(EventTimingAnalysisService eventTimingAnalysisService) {
        this.eventTimingAnalysisService = eventTimingAnalysisService;
    }


    @ApiOperation(value = "搜索引入")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "taskId", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageNum", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "keyword", value = "搜素关键字", required = true)
    })

    @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.Node.class, responseContainer = "List")
    @GetMapping("/event")
    public ResponseEntity<List<GraphNeo4jVO.Node>> listEventNodeByName(@RequestParam Integer taskId,
                                                                       @RequestParam Integer pageNum,
                                                                       @RequestParam Integer pageSize,
                                                                       @RequestParam String  keyword) {
        return ResponseEntity.ok(eventTimingAnalysisService.listEventNodeByName(taskId, pageNum, pageSize, keyword));
    }

    @ApiOperation(value = "同类型事件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "taskId", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", value = "节点id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "labels", value = "节点labels", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageNum", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", required = true),
    })

    @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.Node.class, responseContainer = "List")
    @GetMapping("/same-label-event")
    public ResponseEntity<List<GraphNeo4jVO.Node>> listEventNodeByName(@RequestParam Integer taskId,
                                                                       @RequestParam String nodeId,
                                                                       @RequestParam String  labels,
                                                                       @RequestParam Integer pageNum,
                                                                       @RequestParam Integer pageSize) {
        return ResponseEntity.ok(eventTimingAnalysisService.listSameLabelEventNode(taskId, nodeId, labels, pageNum, pageSize));
    }

    @ApiOperation(value = "共同关联事件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "taskId", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "array", name = "nodeIds", value = "节点ids", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageNum", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", required = true),
    })

    @ApiResponse(code = 200, message = "ok", response = RelEventNode.class, responseContainer = "List")
    @GetMapping("/same-rel-event")
    public ResponseEntity<List<RelEventNode>> listSameRelEventNode(@RequestParam Integer taskId,
                                                               @RequestParam String[] nodeIds,
                                                               @RequestParam Integer pageNum,
                                                               @RequestParam Integer pageSize) {
        return ResponseEntity.ok(eventTimingAnalysisService.listSameRelEventNode(taskId, nodeIds,  pageNum, pageSize));
    }

    @ApiOperation(value = "关联事件")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "taskId", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "nodeId", value = "节点id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageNum", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", required = true),
    })

    @ApiResponse(code = 200, message = "ok", response = RelEventNode.class, responseContainer = "List")
    @GetMapping("/rel-event")
    public ResponseEntity<List<RelEventNode>> listRelEventNode(@RequestParam Integer taskId,
                                                               @RequestParam String nodeId,
                                                               @RequestParam Integer pageNum,
                                                               @RequestParam Integer pageSize) {
        return ResponseEntity.ok(eventTimingAnalysisService.listRelEventNode(taskId, nodeId,  pageNum, pageSize));
    }

    @ApiOperation(value = "事件关联多媒体，参数为节点id")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "array", name = "nodeIds",  value = "节点id"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "taskId", value = "任务id")
    })
    @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.class)
    @GetMapping("/rel-doc/v1")
    public ResponseEntity<List<EventRelDocVO>> eventRelMedia(@RequestParam("nodeIds") String[] nodeIds,
                                                             @RequestParam(value = "taskId")Integer taskId) {
        return ResponseEntity.ok(eventTimingAnalysisService.eventRelMedia(nodeIds, taskId));
    }


    @ApiOperation(value = "事件关联多媒体,参数为节点")
    @ApiResponse(code = 200, message = "ok", response = GraphNeo4jVO.class)
    @PostMapping("/rel-doc")
    public ResponseEntity<List<EventNodeRelMediaVO>> eventRelMedia2(@RequestBody List<GraphNeo4jVO.Node> nodes,
                                                                    @RequestParam Integer taskId) {
        return ResponseEntity.ok(eventTimingAnalysisService.eventRelMedia2(nodes, taskId));
    }
}
